package com.example.tian.securityinspection.module.library;

import android.content.Context;

import com.example.tian.securityinspection.context.AppCookie;
import com.example.tian.securityinspection.module.qualifiers.ApplicationContext;
import com.example.tian.securityinspection.module.qualifiers.CacheDirectory;
import com.example.tian.securityinspection.module.qualifiers.ShareDiretory;
import com.example.tian.securityinspection.network.RestApiClient;

import java.io.File;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

import static com.example.tian.securityinspection.util.Constants.Persistence.SHARE_FILE;

@Module(
        library = true,
        includes = ContextProvider.class
)
public class NetworkProvider {

    @Provides
    @Singleton
    public RestApiClient provideRestApiClient(@CacheDirectory File cacheLocation, @ApplicationContext Context context){
        RestApiClient restApiClient = new RestApiClient(context,cacheLocation);

        if (AppCookie.isLoggin()){
            //这个是用来请求token的,没有可以注释掉
            //restApiClient.setToken(AppCookie.getAccessToken());
        }

        return restApiClient;
    }

    @Provides
    @Singleton
    @CacheDirectory
    public File provideHttpCacheLocation(@ApplicationContext Context context){
        return context.getCacheDir();
    }

    @Provides
    @Singleton
    @ShareDiretory
    public File provideShareLocation(@ApplicationContext Context context){
        return new File(context.getFilesDir(), SHARE_FILE);
    }


}
